<style>
    .layui-input-inline{margin-top:10px;}
</style>
<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>资金归集</cite></a>
        <a><cite>分账管理</cite></a>
        <a><cite>分账商户</cite></a>
    </span>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">分账商户列表</li>
            </ul>
            <div class="layui-tab-content">

                <div class="layui-row">
                    <div class="layui-form" style="float:right;">
                        <div class="layui-form-item" style="margin:0;">
                            <div class="layui-input-inline">
                                <select id="searchInfoType"><option value="">用户类型</option><option value="1">代理商</option><option value="2">商户</option></select>
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" id="searchInfoId" autocomplete="off" placeholder="用户ID" class="layui-input">
                            </div>

                            <div class="layui-input-inline" >
                                <select id="searchIfTypeCode"><option value="">渠道接口类型</option></select>
                            </div>
                            <div class="layui-input-inline" >
                                <input type="text" id="searchChannelMchId" placeholder="渠道商户号" required lay-verify="required"  autocomplete="off" class="layui-input">
                            </div>

                            <a id="search" style="margin-top: 10px" class="layui-btn"><i class="layui-icon layui-icon-search"></i>搜索</a>
                        </div>
                    </div>
                </div>

                <div class="layui-row">
                    <div class="layuiAdmin-btns" style="margin: 10px 0;">
                        <a class="layui-btn create" data-type="all" data-events="create"><i class="layui-icon layui-icon-add-1"></i>新增分账用户</a>
                    </div>
                </div>
                <table class="layui-hide center" id="cList" lay-filter="cList"></table>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['table','util', 'form', 'admin'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,element = layui.element
        ,view = layui.view
        ,admin = layui.admin;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        //标题内容模板
        var tplTitle = function(d){
            // return '<a class="layui-btn layui-btn-sm" lay-href="config/division_mch/update/id='+ d.id +'">编辑</a>'
            return "<a class='layui-btn layui-btn-xs' lay-event='edit'><i class='layui-icon layui-icon-edit'></i>编辑</a>";
        };

        // 加载支接口类型
        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/common/pay_interface_type_all',
            async: false,
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0){
                    var ifTypeList = res.data;
                    //遍历赋值
                    $.each(ifTypeList, function(){
                        $("#ifTypeCode").append('<option value= '+this.ifTypeCode+'>['+this.ifTypeCode+']'+this.ifTypeName+'</option>');
                    });
                    form.render('select');
                }
            }
        });




        table.render({
            elem: '#cList'
            ,url: layui.setter.baseUrl + '/config/division/mch/list'
            ,where: { access_token: layui.data(layui.setter.tableName).access_token }
            ,id: 'tableReload'
            ,cols: [[
                {field:'infoId', title: '系统用户ID'}
                ,{title: '用户类型', templet:'<div>{{ d.infoType =="1" ? "代理商":"商户" }}</div>' }
                ,{field: 'ifTypeCode',  title: '上游渠道接口类型'}
                ,{field:'channelMchId',  title: '上游用户ID'}
                ,{field:'remark',  title: '备注'}
                ,{field: 'createTime', title: '创建时间', width: 200, templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
                ,{field:'edite', width: 100, fixed: "right", title: '操作', templet: tplTitle }
            ]]
            ,page: true
            ,skin: 'line'
        });

        //监听工具条
        table.on('tool(cList)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                view.xxpayPopup("编辑", "cash_coll/division/division_mch/update", {id: data.id}, {area:['70%','60%']});
            }
        });

        $('.create').click(function(){
            view.xxpayPopup("新增分账用户", "cash_coll/division/division_mch/create", {null: null}, {area:['70%','70%']});
        });

        // 渲染表单
        form.render();

        $('#search').on('click', function() {
            var infoType = $("#searchInfoType").val();
            var infoId = $("#searchInfoId").val();
            var ifTypeCode = $("#searchIfTypeCode").val();
            var channelMchId = $("#searchChannelMchId").val();
            //执行重载
            table.reload('tableReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    infoType: infoType,
                    infoId: infoId,
                    ifTypeCode : ifTypeCode,
                    channelMchId : channelMchId
                }
            });
        });

    });
    
</script>
